home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Web;
- using System.Web.Services;
-
- namespace MathService
- {
-
- [WebService(Namespace="http://www.bigatti.it/namespaces")]
- public class GenericStats : System.Web.Services.WebService
- {
-
- public GenericStats()
- {
- //CODEGEN: chiamata richiesta da Progettazione servizi Web ASP.NET.
- InitializeComponent();
- }
-
- #region Codice generato da Progettazione componenti
-
- //Richiesto da Progettazione servizi Web
- private IContainer components = null;
-
- /// <summary>
- /// Metodo necessario per il supporto della finestra di progettazione. Non modificare
- /// il contenuto del metodo con l'editor di codice.
- /// </summary>
- private void InitializeComponent()
- {
- }
-
- /// <summary>
- /// Pulire le risorse in uso.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if(disposing && components != null)
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #endregion
-
- [WebMethod(Description="Calcola una serie di statistiche sulla serie di numeri passata come parametro")]
- public GenericMathData compute( string valueString )
- {
- GenericMathData result = new GenericMathData();
- result.min = 0;
- result.max = 0;
-
- double sum = 0;
- double squaredSum = 0;
-
- char[] delimiters = ";".ToCharArray();
- string[] values = valueString.Split( delimiters );
-
- result.counter = values.Length;
- for( int i = 0; i < result.counter; i++ )
- {
- float value = float.Parse( values[ i ] );
-
- sum += value;
- squaredSum += value * value;
-
- result.min = ( value < result.min || i == 0 ) ? value : result.min;
- result.max = ( value > result.max) ? value : result.max;
- }
-
- result.mean = (float)(sum / result.counter);
- result.standardDeviation = (float)
- ( Math.Sqrt( squaredSum - ( result.mean * result.mean ) /
- (result.counter-1) )
- );
- result.coefficientOfVariation =
- result.standardDeviation / result.mean;
-
- return result;
- }
-
- public struct GenericMathData
- {
- public float mean;
- public float standardDeviation;
- public float coefficientOfVariation;
- public int counter;
- public float min;
- public float max;
- }
- }
- }
-
-